import { BaseWindow } from "../../../../component/window/BaseWindow";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { Cache } from "../../../cache/Cache";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { StringHelper } from "../../../../../com/gengine/utils/StringHelper";
import { MsgManager } from "../../../manager/MsgManager";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GTextInput } from "../../../../../com/mui/controls/GTextInput";
//class GuildMassSendWindow
    
    export  class GuildMassSendWindow extends BaseWindow
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this.setSize(470, 365);
            this.title = Language.getString(57175);
            this.titleHeight = 28;
            ObjCreate.createBg(20, 40, 430, 320, this);
            ObjCreate.createGTextField(Language.getString(57176), 25, 52, 100, 20, this);
            this._receiveInput = ObjCreate.createGTextInput(75, 50, 100, 20, this);
            this._receiveInput.text = Language.getString(57177);
            this._receiveInput.editable = false;
            ObjCreate.createGTextField(Language.getString(57178), 255, 52, 100, 20, this);
            this._senderInput = ObjCreate.createGTextInput(310, 50, 100, 20, this);
            this._senderInput.text = Cache.instance.role.entityInfo.name;
            this._senderInput.editable = false;
            ObjCreate.createGTextField(Language.getString(57179), 25, 80, 100, 20, this);
            this._titleInput = ObjCreate.createGTextInput(75, 80, 180, 20, this);
            ObjCreate.createBg(20, 100, 435, 28, this, ImagesConst.RbListHeader);
            ObjCreate.createGTextField(Language.getString(57180), 200, 105, 100, 20, this, new GTextFormat(FontUtil.songtiName, 14, 15788607));
            this._contentInput = ObjCreate.createGTextInput(25, 130, 420, 190, this);
            this._clearBtn = ObjCreate.createGButton(Language.getString(57181), 35, 325, 60, 24, this);
            this._clearBtn.name = "clearBtn";
            this._clearBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            this._sendWinBtn = ObjCreate.createGButton(Language.getString(57182), 280, 325, 70, 24, this);
            this._sendWinBtn.name = "sendWinBtn";
            this._sendWinBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            this._sendMailBtn = ObjCreate.createGButton(Language.getString(57183), 360, 325, 70, 24, this);
            this._sendMailBtn.name = "sendMailBtn";
            this._sendMailBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            this.regToolTip();
            return;
        }

        /* internal  */regToolTip(): void
        {
            this._clearBtn.toolTipData = Language.getString(57184);
            this._sendWinBtn.toolTipData = Language.getString(57185);
            this._sendMailBtn.toolTipData = Language.getString(57186);
            return;
        }

        /* internal  */onBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=this._titleInput.text;
            var loc2=this._contentInput.text;
            var loc3;
            if ((loc3 = (arg1.target as GButton).name) == "clearBtn") 
            {
                this._contentInput.text = "";
            }
            if (StringHelper.getCharLength(loc1) > 20) 
            {
                MsgManager.showRollTipsMsg(Language.getString(57187));
                return;
            }
            if (loc3 != "sendWinBtn") 
            {
                if (loc3 == "sendMailBtn") 
                {
                    if (StringHelper.getCharLength(loc1) == 0) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(57189));
                        return;
                    }
                    if (StringHelper.getCharLength(loc2) > 1200) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(57190));
                        return;
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildSendMail, {"title": loc1, "content": loc2}));
                }
            }
            else 
            {
                if (StringHelper.getCharLength(loc2) > 100) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(57188));
                    return;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.GuildSendChat, loc1 + "\n" + loc2));
                this.clear();
            }
            return;
        }

        public clear(): void
        {
            this._titleInput.text = "";
            this._contentInput.text = "";
            return;
        }

        /* internal */ /* var */_receiveInput: GTextInput;

        /* internal */ /* var */_senderInput: GTextInput;

        /* internal */ /* var */_titleInput: GTextInput;

        /* internal */ /* var */_contentInput: GTextInput;

        /* internal */ /* var */_clearBtn: GButton;

        /* internal */ /* var */_sendWinBtn: GButton;

        /* internal */ /* var */_sendMailBtn: GButton;
    }
